# -*- coding:utf-8 -*-
"""
@Time : 2025/01/31 15:00 PM
@Author: xiaomi
@Des: mysql数据库
"""

from dotenv import load_dotenv
import os

from tortoise import Tortoise

# 加载 .env 文件
load_dotenv()


# -----------------------MYSQL 数据库配置-----------------------------------
DB_CONFIG_MYSQL = {
    "connections": {
        "base": {
            'engine': 'tortoise.backends.mysql',
            "credentials": {
                'host': os.getenv('BASE_HOST', '127.0.0.1'),
                'user': os.getenv('BASE_USER', 'your_usernae'),
                'password': os.getenv('BASE_PASSWORD', 'your_password'),
                'port': int(os.getenv('BASE_PORT', 3306)),
                'database': os.getenv('BASE_DB', 'your_dbname'),
            }
        },
    },
    "apps": {
        "base": {"models": ["models.base", "aerich.models"], "default_connection": "base"},
    },
    'use_tz': False,
    'timezone': 'Asia/Shanghai'
}

async def init_db():
    await Tortoise.init(config=DB_CONFIG_MYSQL)
    # await Tortoise.generate_schemas()

async def close_db():
    await Tortoise.close_connections()